home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / MPW_TOOL / TOOLS / TOOLS_WI / ICON_8 / ICONT_FO / TMEM.C < prev    next >
Text File  |  1990-03-02  |  3KB  |  107 lines

  1. /*
  2.  * tmem.c -- memory initialization and allocation for the translator.
  3.  */
  4.  
  5. #include "::h:config.h"
  6. #include "tproto.h"
  7. #include "globals.h"
  8. #include "trans.h"
  9. #include "::h:memsize.h"
  10. #include "tsym.h"
  11. #include "tree.h"
  12.  
  13. struct tlentry **lhash;        /* hash area for local table */
  14. struct tgentry **ghash;        /* hash area for global table */
  15. struct tcentry **chash;        /* hash area for constant table */
  16. struct tientry **ihash;        /* hash area for identifier table */
  17.  
  18. nodeptr tree;            /* parse tree space */
  19. nodeptr tend;            /* end of parse tree space */
  20. struct tlentry *ltable;        /* local table */
  21. struct tgentry *gtable;        /* global table */
  22. struct tcentry *ctable;        /* constant table */
  23. struct tientry *itable;        /* identifier table */
  24.  
  25. char *strings;            /* string space */
  26. char *stre;            /* end of string space */
  27.  
  28. nodeptr tfree;            /* free pointer for parse tree space */
  29. struct tlentry *lfree;        /* free pointer for local table */
  30. struct tgentry *gfree;        /* free pointer for global table */
  31. struct tcentry *ctfree;        /* free pointer to constant table */
  32. struct tientry *ifree;        /* free pointer for identifier table */
  33. char *strf;            /* free pointer for string space */
  34.  
  35.  
  36. /*
  37.  * tmalloc - allocate memory for the translator
  38.  */
  39.  
  40. novalue tmalloc()
  41. {
  42.    chash = (struct tcentry **) tcalloc(chsize, sizeof (struct tcentry *));
  43.    ghash = (struct tgentry **) tcalloc(ghsize, sizeof (struct tgentry *));
  44.    ihash = (struct tientry **) tcalloc(ihsize, sizeof (struct tientry *));
  45.    lhash = (struct tlentry **) tcalloc(lhsize, sizeof (struct tlentry *));
  46.  
  47.    ctable = (struct tcentry *) tcalloc(csize, sizeof (struct tcentry));
  48.    gtable = (struct tgentry *) tcalloc(gsize, sizeof (struct tgentry));
  49.    itable = (struct tientry *) tcalloc(isize, sizeof (struct tientry));
  50.    ltable = (struct tlentry *) tcalloc(lsize, sizeof (struct tlentry));
  51.  
  52.    strings = (char *) tcalloc(stsize, sizeof(char));
  53.    stre = strings + stsize;
  54.  
  55.    tree = (nodeptr) tcalloc(tsize, sizeof(word));
  56.    tend = (nodeptr) ((word *)tree + tsize);
  57.    }
  58.  
  59. /*
  60.  * meminit - clear tables for use in translating the next file
  61.  */
  62. novalue tminit()
  63.    {
  64.    register struct tlentry **lp;
  65.    register struct tgentry **gp;
  66.    register struct tcentry **cp;
  67.    register struct tientry **ip;
  68.  
  69.    /*
  70.     * Reset the free pointer for each region.
  71.     */
  72.    lfree = ltable;
  73.    gfree = gtable;
  74.    ctfree = ctable;
  75.    ifree = itable;
  76.    strf = strings;
  77.    tfree = tree;
  78.    /*
  79.     * Zero out the hash tables.
  80.     */
  81.    for (lp = lhash; lp < &lhash[lhsize]; lp++)
  82.       *lp = NULL;
  83.    for (gp = ghash; gp < &ghash[ghsize]; gp++)
  84.       *gp = NULL;
  85.    for (cp = chash; cp < &chash[chsize]; cp++)
  86.       *cp = NULL;
  87.    for (ip = ihash; ip < &ihash[ihsize]; ip++)
  88.       *ip = NULL;
  89.    }
  90.  
  91. /*
  92.  * tmfree - free memory used by the translator
  93.  */
  94. novalue tmfree()
  95.    {
  96.    free((char *) chash);   chash = NULL;
  97.    free((char *) ghash);   ghash = NULL;
  98.    free((char *) ihash);   ihash = NULL;
  99.    free((char *) lhash);   lhash = NULL;
  100.    free((char *) ctable);  ctable = NULL;
  101.    free((char *) gtable);  gtable = NULL;
  102.    free((char *) itable);  itable = NULL;
  103.    free((char *) ltable);  ltable = NULL;
  104.    free((char *) strings); strings = NULL;
  105.    free((char *) tree);    tree = NULL;
  106.    }
  107.